//
//  NSString+ZQQMD5.m
//  ZQQDownLoader
//
//  Created by MoDao-iOS on 2017/7/18.
//  Copyright © 2017年 MoDao-iOS. All rights reserved.
//

#import "NSString+ZQQMD5.h"
#import <CommonCrypto/CommonDigest.h>

@implementation NSString (ZQQMD5)

- (NSString *)md5 {
    const char *cStr = self.UTF8String;
    unsigned char digest[CC_MD5_DIGEST_LENGTH];
    
    // 作用: 把c语言的字符串 -> md5 c字符串
    CC_MD5(cStr, (CC_LONG)strlen(cStr), digest);
    
    // 32
    NSMutableString *result = [NSMutableString stringWithCapacity:CC_MD5_DIGEST_LENGTH * 2];
    
    for (int i = 0; i < CC_MD5_DIGEST_LENGTH; i++) {
        [result appendFormat:@"%02x", digest[i]];
    }
    return result;
}

@end
